exercises

Exercises#

  1. Write a JavaScript program to list the properties of a JavaScript object.

Sample object:

var student = {
name: "David Rayy",
sclass: "VI",
rollno: 12,
};

Sample Output:

name,sclass,rollno
  1. Write a JavaScript program to delete the rollno property from the following object. Also print the object before and after deleting the property.

Sample object:

var student = {
name: "David Rayy",
sclass: "VI",
rollno: 12,
};
  1. Write a JavaScript program to get the length of a JavaScript object properties.

  2. Write a JavaScript function to retrieve all the values of an object's properties. Sample object:

var country = {
name: "France",
capital: "Paris",
};

Sample Output:

["France", "Paris"];
  1. Write a JavaScript function to check whether an object contains given property.

  2. Write a JavaScript function to get a copy of the object where the keys have become the values and the values the keys.

Sample Object:

var colors = {
red: "#FF0000",
green: "#00FF00",
white: "#FFFFFF",
};

Sample Output

{
"#FF0000": "red",
"#00FF00": "green",
"#FFFFFF": "white"
}